package com.link4a.doms.dao.handler;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.link4a.doms.dao.Page;
import com.link4a.doms.dao.SqlSessionTemplateSupport;
import com.link4a.doms.model.Provider;
import com.link4a.doms.vo.ProviderCondition;

@Repository
public class ProviderHandler extends SqlSessionTemplateSupport {

	
	public Provider findById(int id) {
		return getSqlSession().selectOne("findById", id);
	}
	
	public Page<Provider> findPage(ProviderCondition providerCondition) {
		return findPage(providerCondition, "countPage", "findPage");
	}
	
	public void create(Provider provider) {
		getSqlSession().insert("create", provider);
	}
	
	public void update(Provider provider) {
		getSqlSession().update("update", provider);
	}
	
	public void delete(int id) {
		getSqlSession().delete("delete", id);
	}
	
	public boolean isNameDuplicated(Provider provider) {
		return getSqlSession().selectOne("isNameDuplicated", provider) != null;
	}

	public List<Provider> listByKeyword(String keyword) {
		return getSqlSession().selectList("listByKeyword", "%"+keyword+"%");
	}
}